package com.coffee.soft.service.impl;

import com.coffee.soft.entity.Items;
import com.coffee.soft.entity.ItemsCarousel;
import com.coffee.soft.mapper.ItemsMapper;
import com.coffee.soft.service.ItemsShowPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author:LiuRuidong
 * @Description: 商品展示页，商品轮播图和商品上新图
 * @Date: Created in 17:38 2018/2/4
 * @Modified By:
 */
@Service
public class ItemsShowPageServiceImpl implements ItemsShowPageService {

    @Autowired
    private ItemsMapper itemsMapper;
    /**
     * @Author：LiuRuidong
     * @Description: 商品轮播图
     * @Date:2018/2/4 17:52
     * @Param:
     * @return
     */
    @Override
    public List<ItemsCarousel> CarouseItems() {
        List<ItemsCarousel> itemsCarouselsList = new ArrayList();
        ItemsCarousel itemsCarousel = null;
//      查询出来轮播的商品
        List<Items> itemsList =itemsMapper.selectItemsCarousel();
        Iterator<Items> iterator = itemsList.iterator();
        while(iterator.hasNext()){
            itemsCarousel = new ItemsCarousel();
            Items items = iterator.next();
            itemsCarousel.setItemsId(items.getItemsId());
            itemsCarousel.setCarouselPicture(items.getCarouselPicture());
            itemsCarouselsList.add(itemsCarousel);
        }
        return itemsCarouselsList;
    }
/**
 * @Author：LiuRuidong
 * @Description: 商品上新图
 * @Date:2018/2/5 15:37
 * @Param:
 * @return
 */
    @Override
    public List<ItemsCarousel> OnTheNewItems() {
        //        用于重新封装
        List<ItemsCarousel> itemsNewList = new ArrayList();

//      查询出来上新的商品，图片格式也是轮播的那种图片
        List<Items> itemsList = itemsMapper.selectNewImage();
        Iterator<Items> iterator = itemsList.iterator();
        ItemsCarousel itemsNew = null;
        while(iterator.hasNext()){
            itemsNew = new ItemsCarousel();
            Items items = iterator.next();
            itemsNew.setItemsId(items.getItemsId());
            itemsNew.setCarouselPicture(items.getCarouselPicture());
            itemsNewList.add(itemsNew);
        }
        return itemsNewList;
    }
}
